package com.content.scaffold.common.event;



import com.content.scaffold.common.web.RequestContext;
import com.content.scaffold.common.web.RequestInfo;
import lombok.Getter;
import org.springframework.context.ApplicationEvent;

/**
 * @author xiaojl
 */
@Getter
public class BaseAsyncEvent<T> extends ApplicationEvent {

    private final String type;
    private final RequestInfo requestInfo;
    private final T source;

    public BaseAsyncEvent(T source, String type) {
        super(source);
        this.source = source;
        this.type = type;
        this.requestInfo = RequestContext.getRequestInfo();
    }
    public void loadRequestInfo() {
        if (null != requestInfo) {
            RequestContext.setRequestInfo(requestInfo);
        }
    }

    public void releaseRequestInfo() {
        RequestContext.clear();
    }

}